package com.tukez.tmdb

import scala.concurrent.ops.future
import http.HttpResponse
import com.tukez.tmdb.query.Order
import com.tukez.tmdb.query.OrderBy
import org.joda.time.DateTimeZone
import com.tukez.tmdb.model.Movie
import org.specs2.ScalaCheck
import org.joda.time.Duration

class TMDbMovieSpecBase extends TMDbSpecBase with ScalaCheck {

  def checkOneMovie(movie: Movie) = {
    movie.id must_== 3784
    movie.name must_== "Frankie and Johnny"

    movie.released.getYear must_== 1991
    movie.released.getMonthOfYear must_== 10
    movie.released.getDayOfMonth must_== 18

    movie.posters map { _.width } must_== List(92, 154, 185, 342, 500, 1021)
    movie.posters forall { _.`type` == "poster" } must beTrue

    movie.backdrops map { _.width } must_== List(300, 780, 1280, 1280)
    movie.backdrops forall { _.`type` == "backdrop" } must beTrue

    movie.last_modified_at.toDateTime(DateTimeZone.UTC).toString() must_== "2011-11-16T23:20:11.000Z"

    movie.opt.alternative_name must_== Some("Paura d'amare")
    movie.opt.score must_== None
    movie.opt.imdb_id must_== Some("tt0101912")
    movie.opt.runtime must_== Some(Duration.standardMinutes(118))

    movie.details must_== None
  }

  def checkThreeMovies(movie1: Movie, movie2: Movie, movie3: Movie) = {
    movie1.id must_== 3784
    movie2.id must_== 4808
    movie3.id must_== 746

    movie1.name must_== "Frankie and Johnny"
    movie2.name must_== "Charade"
    movie3.name must_== "The Last Emperor"

    movie1.posters map { _.width } must_== List(92, 154, 185, 342, 500, 1021)
    movie2.posters map { _.width } must_== List(92, 185, 342, 500, 600)
    movie3.posters map { _.width } must_== List(92, 154, 185, 342, 500, 1000)

    movie1.backdrops map { _.width } must_== List(300, 780, 1280, 1280)
    movie2.backdrops map { _.width } must_== List(780, 1280, 1920)
    movie3.backdrops map { _.width } must_== List(300, 780, 1280, 1280)

    movie1.last_modified_at.toDateTime(DateTimeZone.UTC).toString() must_== "2011-11-16T23:20:11.000Z"
    movie2.last_modified_at.toDateTime(DateTimeZone.UTC).toString() must_== "2011-11-17T13:11:33.000Z"
    movie3.last_modified_at.toDateTime(DateTimeZone.UTC).toString() must_== "2011-11-17T16:12:51.000Z"

    movie1.opt.score must_== None
    movie2.opt.score must_== None
    movie3.opt.score must_== Some(5.6)

    movie1.details must_== None
    movie2.details must_== None
    movie3.details must_== None
  }

  def checkDetailedMovie(movie: Movie) = {
    movie.id must_== 187
    movie.name must_== "Sin City"
      
    movie.posters map { _.width } must_== List(920, 154, 185)
    movie.posters forall { _.`type` == "poster" } must beTrue

    movie.backdrops map { _.width } must_== List(300, 7800, 1280)
    movie.backdrops forall { _.`type` == "backdrop" } must beTrue

    movie.details must beSome
    val details = movie.details.get

    details.budget must_== 40000000
    details.tagline must_== "There is no justice without sin."
    details.keywords must have size 18
    details.genres map { _.id } must_== List(28, 80, 18, 53)
    details.studios map { _.id } must_== List(20, 334)
    details.languages_spoken map { _.name } must_== List("English")
    details.countries map { _.code } must_== List("US")
    details.cast must have size 3
    details.cast map { _.name } must_== List("Frank Miller", "Frank Miller", "Robert Rodriguez")
    details.cast map { _.id } must_== List(2293, 2293, 2294)
    details.cast map { _.cast_id } must_== List(1, 4, 2)
  }
}